package com.example.demo.Controller;

import com.example.demo.DAO.OrderDAO;
import com.example.demo.DAO.ShopDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class OrderC {
    @Autowired
    OrderDAO orderDAO;
    @Autowired
    ShopDAO shopDAO;

    @RequestMapping("/order_ect")
    public String order_ect(HttpServletRequest request, Model model) {
        String aucId = request.getParameter("aucId");
        String user = request.getParameter("user");
        double aucPrice = shopDAO.selectPrice(aucId);
        orderDAO.insert_order(user, aucId, aucPrice);
        model.addAttribute("name", user);
        model.addAttribute("order_list", orderDAO.selectId(user));
        return "order_ex";
    }

    @RequestMapping("/user_del")
    public String manage_del(HttpServletRequest request, Model model) {
        String aucId = request.getParameter("aucId");
        String user = request.getParameter("user");
        orderDAO.delete_user(aucId, user);
        model.addAttribute("name", user);
        model.addAttribute("order_list", orderDAO.selectId(user));
        return "order_ex";
    }

    @RequestMapping("/user_order")
    public String user_order(HttpServletRequest request, Model model) {
        String user = request.getParameter("user");
        model.addAttribute("name", user);
        model.addAttribute("order_list", orderDAO.selectId(user));
        return "order_ex";
    }

    @RequestMapping("/user_shop")
    public String user_shop(HttpServletRequest request, Model model) {
        String user=request.getParameter("user");
        model.addAttribute("name",user);
        model.addAttribute("shop_list",shopDAO.selectAll());
        return "Shop";
    }

}
